package com.yangchao.webflux;

import java.util.ArrayList;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

public class chat02mapMulti {
    public static void main(String[] args) {
        List<Student2> students = new ArrayList<>();
        students.add(new Student2("张;三", 18));
        students.add(new Student2("李四", 19));
        students.add(new Student2("王五", 20));
        // 使用flatMap来处理包含分号的学生名字，拆分成多个学生对象
        List<Student2> objectStream = students.stream().mapMulti(new BiConsumer<Student2, Consumer<Student2>>() {
                                                                     @Override
                                                                     public void accept(Student2 stu, Consumer<Student2> objectConsumer) {
                                                                         objectConsumer.accept(stu);
                                                                         stu.setName("replace" + stu.name);
                                                                         objectConsumer.accept(stu);
                                                                     }
                                                                 }

        ).toList();
        objectStream.forEach(System.out::println);
    }
}
